/**
 * 档案借阅----待审核
 */
import React from "react";
import PropTypes from "prop-types";
import { routerRedux } from "dva/router";
import { connect } from "dva";
import { Row, Col, Button, Table } from "antd";
import { filterState, filterMediumType } from "utils/filter";
import { formatDate } from "utils";
import Modal from "./Modal";
import BorrowModal from "./BorrowAgainModal";

let recordItem = "";

class Checking extends React.Component {
  constructor(props) {
    super(props)

    this.state = {

    }

  }


  componentDidMount(){
    const { getList,menu,pagination } = this.props
    const params = {
      operatingState:menu,
      page:pagination.current
    }
    getList(params)
  }
  render() {
    const { menu, list, loading,pagination, modalVisibleChecking, currentItem, showBorrowCheckModal,dispatch } = this.props
    // console.log(menu)
    const columns = [
      {
        title: "档案年度",
        key: "documentYear",
        dataIndex: "documentYear"
      },
      {
        title: "公证事项",
        key: "notarialMatters",
        dataIndex: "notarialMatters",
        render: (text, record) => {
					const datas = text.split("#")
					const ary = []
					datas.map((item, i) => {
						ary.push(
							<p>{item}</p>
						)
					})
					return ary
				}
      },
      {
        title: "申请人",
        key: "applyName",
        dataIndex: "applyName",
        render: (text, record) => {
					const datas = text.split("#")
					const ary = []
					datas.map((item, i) => {
						ary.push(
							<p>{item}</p>
						)
					})
					return ary
				}
      },
      {
        title: "收件日期",
        key: "createdTime",
        dataIndex: "createdTime",
        render: (record, text) => formatDate(record)
      },
      {
        title: "公证日期",
        key: "notarizationAt",
        dataIndex: "notarizationAt",
        render: (record, text) => formatDate(record)
      },
      {
        title: "承办人",
        key: "contractorUserName",
        dataIndex: "contractorUserName"
      },
      {
        title: "建档人",
        key: "createdUserName",
        dataIndex: "createdUserName"
      },
      {
        title: "归属机构",
        key: "organizationName",
        dataIndex: "organizationName"
      },
      {
        title: "借阅人",
        key: "borrowUserName",
        dataIndex: "borrowUserName"
      },
      {
        title: "申请提交日期",
        key: "borrowApplyTime",
        dataIndex: "borrowApplyTime",
        render: (record, text, index) => formatDate(record)
      },
      {
        title: "操作",
        key: "operation",
        render: (record, text, index) => {
          recordItem = record;
          return (
            <div>
              {record.renew != undefined ? (
                <a
                  style={{ paddingLeft: 20 }}
                  onClick={() => showAgainModal(record)}
                >
                  续借审核
              </a>
              ) : (
                  <div>
                    {/* <a onClick={() => showModal(record)}>审核</a> */}
                    <a style={{ marginLeft: 10 }} onClick={() => getSliderDetails(record)}>审核</a>
                  </div>
                )}


            </div>
          );
        }
      }
    ];
    const getWorkHistory = payload => {
      dispatch({
        type: "borrow/getworkflowHistory",
        payload: { processInstanceId: payload.processInstanceId }
      })
    }
    const getSliderDetails = record => {
      getWorkHistory(record)
      dispatch({
        type: "borrow/getSliderDetails",
        payload: { record }
      })
      dispatch({
        type: "borrow/getSliderDetail",
        payload: record
      });
      $("#sliderDetails").animate({ right: "0" });
    };
    const showModal = record => {
      dispatch({
        type: "borrow/getDetail",
        payload: record
      });
    };
    const showAgainModal = record => {
      dispatch({
        type: "borrow/showAgainModal",
        payload: record
      });
    };
    const hideModal = (value, flag) => {
      //	const borrowState = flag ? 1 : 2;
      const borrowState = 2;
      dispatch({
        type: "borrow/updateApplication",
        payload: { ...value, borrowState }
      });
      dispatch({
        type: "borrow/hideCheckingModal"
      });
    };

    const handleOk = (value, flag) => {
      //  const borrowState = flag ? 1 : 2;
      const borrowState = 1;
      dispatch({
        type: "borrow/updateApplication",
        payload: { ...value, borrowState }
      });
      dispatch({
        type: "borrow/hideCheckingModal"
      });
    };

    const tabProps = {
      dataSource: list,
      columns,
      pagination,
      loading: loading.effects['borrow/query'],
      // rowKey: record => record.id,
      onChange(page) {
        dispatch({
          type: "borrow/query",
          payload: { page: page.current, pageSize: page.pageSize }
        });
      }
    };
    const handleOk1 = params => {
      dispatch({
        type: "borrow/borrowAgainCheck",
        payload: {
          ...params
        }
      });
    };
    const hideModal1 = params => {
      // dispatch({
      //   type: "borrow/hideCheckingModal"
      // });
      dispatch({
        type: "borrow/borrowAgainCheck",
        payload: {
          ...params
        }
      });
    };
    const modalProps = {
      title: "借阅审核",
      cancelText: "拒绝",
      okText: "通过",
      visible: modalVisibleChecking,
      onOk: handleOk,
      onCancel: hideModal,
      currentItem
    };
    const checkProps = {
      title: "续借审核",
      cancelText: "拒绝",
      okText: "通过",
      visible: showBorrowCheckModal,
      onOk: handleOk1,
      onCancel: hideModal1,
      currentItem
    };
    return (
      <div>
        <Table {...tabProps} />
        {modalVisibleChecking && <Modal {...modalProps} />}
        {showBorrowCheckModal && <BorrowModal {...checkProps} />}
      </div>
    );
  };
}
Checking.propTypes = {
  location: PropTypes.object,
  borrow: PropTypes.object,
  dispatch: PropTypes.func,
  loading: PropTypes.object
};

export default connect(({ loading, borrow }) => ({ loading, borrow }))(
  Checking
);
